#!/usr/local/bin/lua
--
--	Chapter 02	-	Table
--
--	Michael Ge
--	2014.05.15
--

print("====================")

a = {}
k = "x"
a[k] = 10
a[20] = "great"
print(a["x"])
k = 20
print(a[k])
a["x"] = a["x"] + 1
print(a["x"])

print("====================")

a = {}
a["x"] = 10
b = a
print(b["x"])
b["x"] = 20
print(a["x"])
a = nil
b = nil

print("====================")

a = {}
for i = 1, 1000 do
	a[i] = i * 2
end
print(a[9])
a["x"] = 10
print(a["x"])
print(a["y"])

print("====================")

a.x = 10
print(a.x)
print(a.y)

print("====================")

a = {}
x = "y"
a[x] = 10
print(a[x])		-- a["y"]
print(a.x)		-- a["x"]
print(a.y)		-- a["y"]

print("====================")

a = {}
for i = 1, 10 do
	a[i] = io.read()
end

for i = 1, #a do
	print(a[i])
end

v = -1

print(a[#a])
a[#a] = nil
a[#a + 1] = v

print("====================")

a = {}
a[10000] = 1
print(#a)

print(table.maxn(a))

print("====================")

i = 10; j = "10"; k = "+10"
a = {}
a[i] = "one value"
a[j] = "another value"
a[k] = "yet another value"

print(a[j])
print(a[k])
print(a[tonumber(j)])
print(a[tonumber(k)])

print("====================")